home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / asm / fpanel.com / FPANEL.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-09-05  |  10.8 KB  |  429 lines

  1. page
  2. page  84,132
  3. title -- PFANEL.ASM --   PC Front Panel Simulation
  4. cseg    segment para public 'CODE'
  5.         org     100H
  6.         assume  cs:cseg,ds:cseg
  7. start:
  8.         jmp     initialize
  9.  
  10. dspflg          db      0
  11. dspseg          dw      0
  12. curcol          dw      0
  13. old_timer       dd      ?
  14. old_prtsc_io    dd      ?
  15. remove_msg    label  byte
  16.                 db 'FPANEL has been successfully removed from memory.'
  17.                 db 0dh,0ah,'$'
  18. rem_err_msg   label  byte
  19.                 db 'FPANEL was not removed properly! '
  20.                 db 'Reboot system to completely remove it.'
  21.                 db  0dh,0ah,'$'
  22.  
  23. timer_int       proc    far
  24.         sti
  25.         pushf
  26.         assume  ds:nothing
  27.         call    old_timer
  28.         push    es
  29.         push    ds
  30.         push    bp
  31.         mov     bp,sp
  32.         call    timer
  33.         pop     bp
  34.         pop     ds
  35.         pop     es
  36.         iret
  37. timer_int       endp
  38.  
  39. timer   proc    near
  40.         assume  cs:cseg,ds:cseg
  41.         push    ax
  42.         push    bx
  43.         push    cx
  44.         push    dx
  45.         push    si
  46.         push    di
  47.         push    ds
  48.         mov     bx,cs
  49.         mov     ds,bx
  50.         xor     bx,bx
  51.         mov     cs:curcol,bx
  52.           ; The stack looks like this:
  53.           ;                       New stack since bp saved
  54.           ;       [BP]    word    Old value of BP
  55.           ;       [BP+2]  word    Value of DS reg.
  56.           ;       [BP+4]  word    Value of ES reg.
  57.           ;       [BP+6]  word    Offset of calling address
  58.           ;       [BP+8] word    Segment of calling address
  59.           ;       [BP+10]  word    flags at interrupt
  60.         mov     si,offset ipreg
  61.         call    dstring
  62.         mov     ax,word ptr ss:[bp+8] ; seg of addr
  63.         call    dsword
  64.         call    dcolon
  65.         mov     ax,word ptr ss:[bp+6] ; Offset of addr
  66.         call    dsword
  67.         cmp     byte ptr dspflg,0
  68.         jz      enddsp
  69.         mov     si,offset flgreg
  70.         call    dstring
  71.         mov     ax,word ptr ss:[bp+10]
  72.         and     ax,0fd5H
  73.         call    dsword
  74.         mov     si,offset ssreg
  75.         call    dstring
  76.         mov     ax,ss
  77.         call    dsword
  78.         mov     si,offset esreg
  79.         call    dstring
  80.         mov     ax,word ptr ss:[bp+4]
  81.         call    dsword
  82.         mov     si,offset dsreg
  83.         call    dstring
  84.         mov     ax,word ptr ss:[bp+2]
  85.         call    dsword
  86. enddsp:
  87.         pop     ds
  88.         pop     di
  89.         pop     si
  90.         pop     dx
  91.         pop     cx
  92.         pop     bx
  93.         pop     ax
  94.         ret
  95. timer           endp
  96.  
  97. ;       AX contains singleword to be displayed
  98. dsword          proc    near
  99.         push    ax              ;Save low byte temporarily
  100.         mov     al,ah           ;Move high byte to low byte
  101.         call    dbyte           ;Display high byte
  102.         pop     ax              ;Restore low byte
  103.         call    dbyte           ;Display low byte
  104.         ret
  105. dsword          endp
  106.  
  107. ;       AL contains byte to be displayed
  108. dbyte              PROC NEAR
  109.                    PUSH CX
  110.                    PUSH AX
  111.                    MOV  CX,4
  112.                    AND  AL,0F0H
  113.                    SHR  AL,CL
  114.                    CALL NYBBLE_TO_HEX_DIGIT
  115.                    CALL DCHAR
  116.                    POP  AX
  117.                    CALL NYBBLE_TO_HEX_DIGIT
  118.                    CALL DCHAR
  119.                    POP  CX
  120.                    RET
  121. dbyte              ENDP
  122.  
  123. ;_____________________________________________________________________________;
  124. ;    This procedure converts a nybble (4 bits) to an ASCII (hex) character.   ;
  125. ;                                                                             ;
  126. ;                  AL   nybble to be converted                                ;
  127. ;    Returns:      AL   ASCII character (hex digit)                           ;
  128. ;_____________________________________________________________________________;
  129. NYBBLE_TO_HEX_DIGIT     PROC  NEAR
  130.                    AND  AL,0FH
  131.                    ADD  AL,'0'
  132.                    CMP  AL,'9'
  133.                    JLE  NYBBLE_END
  134.                    ADD  AL,'A'-':'
  135. NYBBLE_END:        RET
  136. NYBBLE_TO_HEX_DIGIT     ENDP
  137.  
  138. ; Display a colon
  139. dcolon          proc    near
  140.         mov     al,':'
  141.         call    dchar
  142.         ret
  143. dcolon          endp
  144.  
  145. ; Display string pointer to by SI
  146. dstring         proc    near
  147. nxtchr:
  148.         cmp     byte ptr cs:[si],0
  149.         je      strdone
  150.         mov     al,byte ptr cs:[si]
  151.         call    dchar
  152.         inc     si
  153.         jmp     nxtchr
  154. strdone:
  155.         ret
  156. dstring         endp
  157.  
  158. dspmsg          proc    near
  159.         push    ax
  160.         push    dx
  161.         push    ds
  162.         push    cs
  163.         pop     ds
  164.         mov     dx,si
  165.         mov     ah,9
  166.         int     21h
  167.         pop     ds
  168.         pop     dx
  169.         pop     ax
  170.         ret
  171. dspmsg          endp
  172. ; Display the character contained in AL
  173. dchar           proc    near
  174.         push    ax
  175.         push    bx
  176.         push    ds
  177.         mov     bx,cs:dspseg
  178.         mov     ds,bx
  179.         mov     bx,cs:curcol
  180.         mov     [bx],al
  181.         inc     bx
  182.         inc     bx
  183.         mov     cs:curcol,bx
  184.         pop     ds
  185.         pop     bx
  186.         pop     ax
  187.         ret
  188. dchar           endp
  189.  
  190.  
  191. control_int     proc    far
  192.         sti
  193.         push    ax
  194.         push    dx
  195.         push    di
  196.         push    ds
  197.         cbw
  198.         shl     ax,1
  199.         mov     di,ax
  200.         jmp     word ptr optstab[di]
  201. optstab:
  202.         dw      offset resints
  203.         dw      offset setint08
  204.         dw      offset iponly
  205.         dw      offset fulldsp
  206.         dw      offset setabort
  207. exit:
  208.         sti
  209.         pop     ds
  210.         pop     di
  211.         pop     dx
  212.         pop     ax
  213.         iret
  214.  
  215. iponly:
  216.         mov     byte ptr cs:dspflg,0
  217.         jmp     exit
  218.  
  219. fulldsp:
  220.         mov     byte ptr cs:dspflg,1
  221.         jmp     exit
  222.  
  223. setint08:
  224.         cli
  225.         mov     ax,cs
  226.         mov     ds,ax
  227.         mov     dx,offset timer_int
  228.         mov     al,08H
  229.         mov     ah,25H
  230.         int     21H
  231.         jmp     exit
  232.  
  233. resints:
  234.         cli
  235.         mov     dx,cs:word ptr old_timer
  236.         mov     ax,cs:word ptr old_timer[2]
  237.         mov     ds,ax
  238.         mov     al,08H
  239.         mov     ah,25H
  240.         int     21H
  241.         cli
  242.         mov     dx,cs:word ptr old_prtsc_io
  243.         mov     ax,cs:word ptr old_prtsc_io[2]
  244.         mov     ds,ax
  245.         mov     al,05H
  246.         mov     ah,25H
  247.         int     21H
  248.         cli
  249.         xor     dx,dx
  250.         xor     ax,ax
  251.         mov     ds,ax
  252.         mov     al,60H
  253.         mov     ah,25H
  254.         int     21H
  255.         push    cs
  256.         pop     es
  257.         mov     ah,4aH
  258.         xor     bx,bx
  259.         int     21H
  260.         jc      err_exit
  261.         mov     ax,cs:[2ch]
  262.         mov     es,ax
  263.         xor     bx,bx
  264.         mov     ah,4ah
  265.         int     21h
  266.         jc      err_exit
  267.         mov     si,offset cs:remove_msg
  268.         call    dspmsg
  269.         jmp     exit
  270. err_exit:
  271.         mov      si,offset cs:rem_err_msg
  272.         call    dspmsg
  273.         jmp     exit
  274.  
  275. setabort:
  276.         cli
  277.         mov     ax,cs
  278.         mov     ds,ax
  279.         mov     dx,offset new_prtsc_io
  280.         mov     al,05H
  281.         mov     ah,25H
  282.         int     21H
  283.         jmp     exit
  284.  
  285. control_int     endp
  286.  
  287. new_prtsc_io         proc    far
  288.         sti                     ; Abort task via DOS terminate function
  289.         mov     ah,4cH
  290.         int     21H
  291.         iret
  292. new_prtsc_io         endp
  293.  
  294. location        dw      0000H   ;Upper-left corner of screen
  295. ipreg           db      'CS:IP=',0
  296. flgreg          db      ' FLAGS=',0
  297. ssreg           db      ' SS=',0
  298. esreg           db      ' ES=',0
  299. dsreg           db      ' DS=',0
  300.  
  301. initialize:
  302.         xor     di,di
  303.         mov     al,60H
  304.         mov     ah,35H
  305.         int     21H
  306.         cmp     bx,0
  307.         jne     args
  308. inst:
  309.         mov     ah,0fh
  310.         int     10h
  311.         cmp     al,07h
  312.         jne     color
  313.         mov     ax,0b000h
  314.         jmp     short setseg
  315. color:
  316.         mov     ax,0b800h
  317. setseg:
  318.         mov     cs:dspseg,ax
  319.         inc     di
  320.         mov     bx,cs
  321.         mov     ds,bx
  322.         mov     al,08H
  323.         mov     ah,35H
  324.         int     21H
  325.         mov     word ptr old_timer,bx
  326.         mov     word ptr old_timer[2],es
  327.  
  328.         mov     al,05H
  329.         mov     ah,35H
  330.         int     21H
  331.         mov     word ptr old_prtsc_io,bx
  332.         mov     word ptr old_prtsc_io[2],es
  333.  
  334.         mov     dx,offset control_int
  335.         mov     al,60H
  336.         mov     ah,25H
  337.         int     21H
  338.  
  339.         mov     si,offset initmsg
  340.         call    dspmsg
  341.  
  342. args:
  343.         mov     bl,0ffH
  344.         mov     si,80H
  345.         xor     cx,cx
  346.         mov     cl,cs:[si]
  347.         cmp     cx,2
  348.         jg      nxtch
  349.         jmp     intdone
  350. nxtch:
  351.         inc     si
  352.         cmp     byte ptr cs:[si],'/'
  353.         je      decode_opt
  354. cont:
  355.         loop    nxtch
  356.         jmp     intdone
  357.  
  358. decode_opt:
  359.         inc     si
  360.         mov     ah,cs:[si]
  361.         cmp     ah,'a'
  362.         jl      upcase
  363.         sub     ah,' '
  364. upcase:
  365.         cmp     ah,'R'
  366.         je      reset
  367.         cmp     ah,'D'
  368.         je      disp
  369.         cmp     ah,'S'
  370.         je      ip
  371.         cmp     ah,'F'
  372.         je      fuldsp
  373.         cmp     ah,'A'
  374.         jne     cont
  375.         mov     al,4
  376.         jmp     do_opt
  377.  
  378. reset:
  379.         mov     al,0
  380.         jmp     do_opt
  381. disp:
  382.         mov     al,1
  383.         jmp     do_opt
  384. fuldsp:
  385.         mov     al,3
  386.         jmp     do_opt
  387. ip:
  388.         mov     al,2
  389. do_opt:
  390.         int     60H
  391.         xor     bl,bl
  392.         jmp     cont
  393.  
  394. intdone:
  395.         cmp     bl,0H
  396.         jz      nomsg
  397.         mov     si,offset options
  398.         call    dspmsg
  399. nomsg:
  400.         cmp     di,0
  401.         je      init_exit
  402.         mov     dx,offset initialize
  403.         int     27H
  404.  
  405. init_exit:
  406.         mov     ah,4cH
  407.         int     21H
  408.  
  409. initmsg:        db      'Front Panel Display Now Resident'
  410.                 db      0dH,0aH,'$'
  411. options:
  412.                 db      0dH,0aH,'FPANEL Command Line Options:',0dH,0aH
  413.                 db      '/r  Removes FPANEL from Memory and Restores Timer(int 8)'
  414.                 db      0dH,0aH
  415.                 db      '    and PrtSc(int 5) and User(int 60H) interrupts'
  416.                 db      0dH,0aH
  417.                 db      '/d  Display Selected Registers at Top of Screen'
  418.                 db      0dH,0aH
  419.                 db      '/s  Select CS:IP registers only (default selection)'
  420.                 db      0dH,0aH
  421.                 db      '/f  Select CS:IP FLAG SS ES DS Registers'
  422.                 db      0dH,0aH
  423.                 db      '/a  Program Abort function replaces PrtSc function'
  424.                 db      0dH,0aH,'$'
  425.  
  426.  
  427. cseg    ends
  428.         end     start
  429.